package com.china08.yxyapi.api.manage.edu.platform.statistics.weikepandect;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.api.manage.edu.platform.statistics.resourcepandect.ResourceModel;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.service.manage.edu.platform.statistics.WeiKeCountListService;

import io.swagger.annotations.ApiOperation;

/**
 * 教育局平台办公     微课统计    微课统计列表    区县
 * 
 */
@CrossOrigin
@RestController
public class WeikeCountListController extends YxyApiBaseController{
	
	@Autowired
	private WeiKeCountListService weiKeCountListService;
	
	@ApiOperation(value = "微课统计    微课统计列表    区县")
	@ResponseBody
	@RequestMapping(value = "/api_yw/manage/edu/platform/statistics/weikepandect/countlist/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public Page<ResourceModel> precess(HttpServletRequest request, HttpServletResponse response,@RequestBody ReqModel reqModel) {
		if(reqModel.areaSchoolValue.equals("区县")){
			Integer schoolBureauLevel =getProfile(request, response).getSchoolBureauLevel();
	        String districtCode=null;
	        if (schoolBureauLevel==0) {
	        	districtCode=getProfile(request, response).getSchoolAreaIdDistrict();
			}else if(schoolBureauLevel==1){
				districtCode=getProfile(request, response).getSchoolAreaIdCity();
			}else if(schoolBureauLevel==2){
				districtCode=getProfile(request, response).getSchoolAreaIdProvince();
			}
	        Pageable pageable = new PageRequest(reqModel.page, reqModel.size);
	        
	        Page<ResourceModel>  pageLst =  weiKeCountListService.getAreaResourceCount(districtCode,schoolBureauLevel,reqModel.sort,pageable);	 
//	        page2 = new PageImpl<RespModel>(respModelLst, pageable, pageLst.getTotalElements());
	        return pageLst;
		}else{
			return null;
		}
    }
    /*protected static class RespModel extends YxyApiRespModel {
    	
    }*/
    protected static class ReqModel extends YxyApiPageReqModel {
    	//区县或者学校
    	public String  areaSchoolValue;
    	//排序DESC、ASC
    	public String sort="DESC";
    }
}
